$(document).ready(function () {


    $.ajax({
            type: 'post',
            url:"http://39.108.233.68:8080/selAllCity" ,
            success: function (data) {
                console.log(JSON.stringify(data))
                // alert("success");
                for(i in data.data)
                {
                    var tr;
                    tr='<td>'+i+'</td>'+'<td>'+data.data[i].cityname+'</td>'+'<td>'+data.data[i].describetion+'</td>'+'<td>'+'<button id="change_city" onclick="jump('+data.data[i].id+')">修改</button>'+'<button id="delete_city" onclick="delete_city('+data.data[i].id+')">删除</button>'+'</td>'
                    $("#city_tbody").append('<tr>'+tr+'</tr>')
                }
            },
            error: function () {
                alert("error");
            }
        }
    )
    })

$(function () {
    $("#city_searchall").click(function () {
            document.getElementById('city_tbody').innerHTML="";
            $.ajax({
                    type: 'post',
                    url:"http://39.108.233.68:8080/selAllCity" ,
                    success: function (data) {
                        console.log(JSON.stringify(data))
                        // alert("success");
                        for(i in data.data)
                        {
                            var tr;
                            tr='<td>'+i+'</td>'+'<td>'+data.data[i].cityname+'</td>'+'<td>'+data.data[i].describetion+'</td>'+'<td>'+'<button id="change_city" onclick="jump('+data.data[i].id+')">修改</button>'+'<button id="delete_city" onclick="delete_city('+data.data[i].id+')">删除</button>'+'</td>'
                            $("#city_tbody").append('<tr>'+tr+'</tr>')
                        }
                    },
                    error: function () {
                        alert("error");
                    }
                }
            )
        }
    )
})
function jump(a){
    window.location.href="city_change.html?a="+a;
}
function delete_city(id) {
    $.ajax({
            type:"post",
            url:"http://39.108.233.68:8080/delOneCity" ,
            data: {id:id,},
            datatype:'json',
            success: function (data) {
                alert("删除成功");

            },
            error: function () {
                alert("error");
            }
        }
    )
}